
#ifndef ESTRUCTURAS_H
#define ESTRUCTURAS_H

#include "../headers/Constantes_PFS.h"


//typedef struct{
//	pthread_mutex_t enUso;
//	uint32_t nroCluster;
//}__attribute__ ((__packed__)) tarraynroCluster;

//tarraynroCluster arrayNrosClusters[15];


//char * handlerAchivoMapeado;

typedef struct stat tStat;

typedef struct{
	uint8_t bufferCluster[4096];
}__attribute__ ((__packed__)) tCluster;

typedef struct{
	uint8_t bufferBloque[1024];
}__attribute__ ((__packed__)) tBloque;

typedef struct bloqueCaches{
	uint8_t modificado;
	uint32_t orden;
	uint32_t nroBloque;
	tBloque data;
	struct bloqueCaches * sgte;
}__attribute__ ((__packed__)) tCache;


typedef struct nodoCache{
	pthread_mutex_t enUso;
	const char * path;
	tCache *cache;
	uint32_t cant;
	struct nodoCache * sgte;
}__attribute__ ((__packed__)) tNodoCache;

typedef struct nodoCacheFat{
	pthread_mutex_t enUso;
	tCache *cache;
	uint32_t cant;
}__attribute__ ((__packed__)) tCacheFat;

enum NIPC_TYPE {HANDSHAKE=0,
				LECTURA=1,
				LECTURA_OK = 11,
				ESCRITURA=2,
				ESCRITURA_OK=21,
				LECTURA_ERROR=10,
				ESCRITURA_ERROR=20
};

typedef struct t_pedido {
		char lectura_o_escritura;
		int32_t direccionSector;
        char planificador_id[25];
        int32_t conexion_ppd_id;
        int32_t conexion_pfs_id;
        char info[512];
        }__attribute__ ((__packed__)) t_pedido;

typedef struct protocoloNIPC{
		int32_t type;
		int32_t payloadlength;
		t_pedido payload;
		}__attribute__ ((__packed__)) nipc;

typedef struct array_conexiones{
		int32_t enUso;
		int32_t descriptor;
		int32_t pfs_id;
		struct array_conexiones * sgte;
}__attribute__ ((__packed__)) t_conexion;



typedef struct sector{
	char bufferSector[512];
}__attribute__ ((__packed__)) tSector;




typedef struct tbootSector{
	uint8_t  jump[3];
	uint8_t nombre[8]; /*mkdosfs*/
	uint16_t bytesPorSector; /*512*/
	uint8_t sectoresPorCluster; /*1*/
	uint16_t sectoresReservados; /*1*/
	uint8_t numeroDeFat; /*2*/
	uint16_t entradasMaximasDirectorio; /*244*/
	uint16_t sectoresTotalesLittleFat;  /*2880*/
	uint8_t descriptorDeMedio; /*240*/
	uint16_t sectoresPorFat16; /*9*/
	uint16_t sectoresPerHead; /**/
	uint16_t cabezasPorCilindro;
	uint32_t sectoresOcultos;
	uint32_t sectoresTotales;
	uint32_t sectoresPorFat;
	uint16_t extFlags;
	uint16_t fsVersion;
	uint32_t rootDirectoryStart;
	uint16_t fsInfoSector;
	uint16_t sectorBackupBoot;
	uint32_t reserved[12];
	uint8_t nroDriver;
	uint8_t reserved1;
	uint8_t extBootSignature;
	uint32_t idVol;
	uint8_t etiquetaVol[11];
	uint8_t tipoFS[8];
}__attribute__ ((packed)) mbr;

struct tnodo{
	uint32_t entrada;
	struct tnodo *sgte;
	};

typedef struct tnodo *tnodoEntrada;

typedef struct{
		uint8_t orden;
		uint16_t name[5];
		uint8_t atributos;
		uint8_t type;
		uint8_t chksum;
		uint16_t name2[6];
		uint16_t firstcluster; /*debe ser 0 en long entrys*/
		uint16_t name3[2];
	}__attribute__ ((packed)) tLongDirectoryEntry;

typedef struct {
		uint8_t name[8];
		uint8_t extension[3];
		uint8_t atributos;
		uint8_t reservadosNT;
		uint8_t milisecondstamp;
		uint16_t createTime;
		uint16_t createDate;
		uint16_t lastAccess;
		uint16_t dirFirstClusterHI;
		uint16_t timeLastWrite;
		uint16_t dateLastWrite;
		uint16_t dirFirstClusterLO;
		uint32_t size;
	}__attribute__ ((packed)) tDirectoryEntry;

typedef struct listaDeEntradas{
		uint8_t tieneEntradaLarga;
		tLongDirectoryEntry longDirectoryEntry;
		tDirectoryEntry directoryEntry;
		struct listaDeEntradas * sgte;
	} __attribute__ ((packed)) tListaEntradasDeDirectorios;

	typedef struct nodosEntradas {
		char subPath[20];
		struct nodosEntradas *sgte;
	}__attribute__ ((packed)) tNodoSubPaths;


typedef struct entradaLongCommon{
			tLongDirectoryEntry longDirectoryEntry;
			tDirectoryEntry directoryEntry;
		} __attribute__ ((packed)) tDirectoryEntries;

typedef struct nodoCacheEntradasDir{
			char * path;
			tDirectoryEntries entradas;
			int32_t orden;
			struct nodoCacheEntradasDir * sgte;
		}__attribute__ ((__packed__)) tnodoCacheEntradasDir;

		typedef struct config{
					char IP[16];
					int32_t Puerto;
					int32_t cantMaxConexiones;
					int32_t logsActivados;
					char PathArchivoLogs[100];
					char PathArchivoCache[100];
					int32_t tamanoCache;
					int32_t tamanoCacheEntradasDir;
		}__attribute__ ((__packed__)) struct_config;


#endif
